<template>
  <div>
    <h2>App组件</h2>
    <p>App组件</p>

    <!-- 建立父子关系   3.使用 -->
    <MyTest
      v-for="item in goodsList"
      :key="item.id"
      :obj="item"
      @kanyidao="changePrice"
    ></MyTest>
  </div>
</template>

<script>
//建立父子关系  1.导入
import MyTest from './components/MyTest.vue'
export default {
  data () {
    return {
      goodsList: [
        { id: 1, name: '方便面', price: 2.5, info: '好吃不贵' },
        { id: 2, name: '火腿肠', price: 2, info: '价钱合理' },
        { id: 3, name: '卤鸡蛋', price: 1.5, info: '我的最爱' }
      ]
    }
  },
  methods: {
    changePrice (id) {
      console.log(id)
      let row = this.goodsList.find(item => item.id === id)
      row.price--
    }
  },
  //建立父子关系   2.注册
  components: {
    MyTest
  }
}
</script>

<style lang="scss" scoped></style>
